display.setStatusBar( display.HiddenStatusBar )
require("global")

local json      = require "json"
local funCommon = require "common"	
local director  = require("director")
local mainGroup = display.newGroup()

settingSound    = nil
settingMusic    = nil
btSetting = { true, true, true, true }
	
function openSetting()
	local settingGroup = display.newGroup()
	return settingGroup
end
	
function getBtSetting(event)
	local bt = event.target
	if bt.status == true then
		bt.status = false
	else
		bt.status = true
	end
	btSetting[bt.id]     = bt.status
	btSetting[5 - bt.id] = not bt.status
	
	if btSetting[1] == true then
		settingSound = "on"
	else
		settingSound = "off"
	end
	
	if btSetting[2] == true then
		settingMusic = "on"
	else
		settingMusic = "off"
	end 
	
	--saveSetting(settingSound, settingMusic)
	return true
end



-- load setting ban dau
function loadSetting( )
	local setting = funCommon.load( "setting" )
	if setting == nil then
		settingSound = "on"
		settingMusic = "on"
		saveSetting( settingSound, settingMusic )
	else
		settingSound  = setting.sound
		settingMusic  = setting.music
	end
	if settingSound == "on" then
        if settingMusic == "on" then
			btSetting = {true, true, false, false}
		else
		    btSetting = {true, false, true, false}
		end
	elseif settingMusic == "on" then 
			btSetting = {false, true, false, true}
	    else
			btSetting = {false, false, true, true}
	end
end


--
function saveSetting( sound, music)
	flag = true
	local setting = {}
	setting.sound = sound
	setting.music = music
	funCommon.save( "setting", setting )
	return flag
end

--xu ly am thanh
function processSound( soundFile, soundChanel, soundLoop, status )
	if settingSound == "on" then
		local sound = audio.loadSound( soundFile )
		if status == true then
			audio.play( sound,{channel = soundChanel, loops = soundLoop})
		else
			audio.stop( soundChanel )
		end
	end
end

local function main()	
	-- libNetWork = require "libs.libNetwork"
	-- libNetWork.client:connect("127.0.0.1",333)
    mainGroup:insert(director.directorView)
    loadSetting( )		
	director:changeScene("scr.mainGame.scrMainGame")
  --director:changeScene("coup.mainGame.scrMainGame")
  return true
end

main()

--[[
local ftp = require("ftp")
 --ftp://195.222.33.239/pub/games/cod/mod/
local connection = ftp.newConnection{ 
                host = "195.222.33.239", 
                --user = "monkeyde", 
                --password = "A4MUaC8wS8", 
                port = 21 -- Optional. Will default to 21.
        }
 
local onUploadSuccess = function(event)
        print("File uploaded to " .. event.path)
end
 
local onDownloadSuccess = function(event)
        print("File downloaded to " .. event.path)
myText = display.newText("OK", 0, 0, native.systemFont, 16)
myText:setTextColor(255, 255, 255)
end
 
local onAppendSuccess = function(event)
        print("File appended")
end
 
local onError = function(event)
        print("Error: " .. event.error)
end

connection:upload{
        localFile = system.pathForFile("image.jpg", system.ResourcesDirectory),
        remoteFile =  "/public_html/imagei.jpg",
        onSuccess = onUploadSuccess,
        onError = onError
}
        
connection:download{
        remoteFile = "/pub/games/cod/mod/awe_v2.1_client.exe",
        localFile = "awe_v2.1_client.exe",
        onSuccess = onDownloadSuccess,
        onError = onError
}
     
connection:append{
        localFile = system.pathForFile("todaysLog.txt", system.ResourcesDirectory),
        remoteFile = "/public_html/completeLog.txt",
        onSuccess = onAppendSuccess,
        onError = onError
}--]]